#!/usr/bin/env python  
import rospy  
import tf2_ros  
from geometry_msgs.msg import TransformStamped  
  
class OdomToBaseLinkBroadcaster:  
    def __init__(self):  
        # 初始化节点  
        rospy.init_node('odom_to_base_link_broadcaster')  
  
        # 创建TransformBroadcaster对象  
        self.broadcaster = tf2_ros.TransformBroadcaster()  
  
        # 设置变换参数（这里我们假设它们是静态的）  
        # 在实际应用中，这些值可能会根据机器人的实际位置和姿态动态变化  
        translation = (0.0, 0.0, 0.0)  # x, y, z  
        rotation = (0.0, 0.0, 0.0, 1.0)  # 使用四元数表示旋转，这里表示没有旋转  
  
        # 设置变换消息  
        self.transform = TransformStamped()  
        self.transform.header.stamp = rospy.Time.now()  
        self.transform.header.frame_id = "odom"  
        self.transform.child_frame_id = "base_link"  
        self.transform.transform.translation.x = translation[0]  
        self.transform.transform.translation.y = translation[1]  
        self.transform.transform.translation.z = translation[2]  
        self.transform.transform.rotation.x = rotation[0]  
        self.transform.transform.rotation.y = rotation[1]  
        self.transform.transform.rotation.z = rotation[2]  
        self.transform.transform.rotation.w = rotation[3]  
  
        # 设置循环率并广播变换  
        self.rate = rospy.Rate(10.0)  # 每秒发布10次  
        while not rospy.is_shutdown():  
            # 在实际应用中，你可能需要更新变换的timestamp和值  
            # 但在这个例子中，我们保持它们不变  
            self.broadcaster.sendTransform(self.transform)  
            self.rate.sleep()  
  
if __name__ == '__main__':  
    try:  
        odom_to_base_link_broadcaster = OdomToBaseLinkBroadcaster()  
    except rospy.ROSInterruptException:  
        pass